# 代码 4-41
import pandas as pd
order = pd.read_table('../data/meal_order_info.csv',
      sep = ',',encoding = 'gbk')
print('进行转换前订单信息表lock_time的类型为：',
      order['lock_time'].dtypes)
order['lock_time'] = pd.to_datetime(order['lock_time'])
print('进行转换后订单信息表lock_time的类型为：',
      order['lock_time'].dtypes)



# 代码 4-42
print('最小时间为：', pd.Timestamp.min)
print('最大时间为：', pd.Timestamp.max)

# 代码 4-43
dateIndex = pd.DatetimeIndex(order['lock_time'])
print('转换为DatetimeIndex后数据的类型为：\n',type(dateIndex))

periodIndex = pd.PeriodIndex(order['lock_time'],freq = 'S')
print('转换为DatetimeIndex后数据的类型为：\n',type(periodIndex))
# 代码 4-44
year1 = [i.year for i in order['lock_time']]
print('lock_time中的年份数据前5个为：',year1[:5])
month1 = [i.month for i in order['lock_time']]
print('lock_time中的月份数据前5个为：',month1[:5])
day1 = [i.day for i in order['lock_time']]
print('lock_time中的日期数据前5个为：',day1[:5])
weekday1 = [i.day_name for i in order['lock_time']]
print('lock_time中的星期名称数据前5个为：',weekday1[:5])
# print('perioIndex中的星期名称数据前5个为：',periodIndex.weekday1[:5])
print()
# 代码 4-46
## 将lock_time数据向后平移一天
time1 = order['lock_time']+pd.Timedelta(days = 1)
print('lock_time在加上一天前前5行数据为：\n',order['lock_time'][:5])
print('lock_time在加上一天前前5行数据为：\n',time1[:5])
